package com.gitee.mars.marsquickframe.controller;

import com.gitee.mars.marsquickframe.request.SysRoleReq;
import com.gitee.mars.marsquickframe.response.result.R;
import com.gitee.mars.marsquickframe.service.SysRoleService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 控制层
 *
 * @Author wq
 * @Date 2020-12-15
 **/
@RestController
@RequestMapping("admin/sysRole")
@AllArgsConstructor
public class SysRoleController {

    private final SysRoleService sysRoleService;

    /**
     * 新增
     *
     * @param req sysRole
     */
    @PostMapping("/add")
    public R add(@RequestBody SysRoleReq req) {
        sysRoleService.add(req);
        return R.success("新增成功");
    }

    /**
     * 删除
     *
     * @param id ids
     */
    @GetMapping("/delete")
    public R delete(Integer id) {
        sysRoleService.delete(id);
        return R.success("删除成功");
    }

    /**
     * 更新
     *
     * @param req sysRole
     */
    @PostMapping("/update")
    public R update(@RequestBody SysRoleReq req) {
        sysRoleService.updateRole(req);
        return R.success("更新成功");
    }

    /**
     * 详情
     *
     * @param id id
     * @return SysRole
     */
    @GetMapping("/detail")
    public R detail(Integer id) {
        return R.success(sysRoleService.detail(id));
    }

    /**
     * 分页
     *
     * @return IPage<SysRole>
     */
    @PostMapping("/page")
    public R pageRole(@RequestBody(required = false) SysRoleReq req) {
        return R.success(sysRoleService.rolePage(req));
    }

    /**
     * 角色列表
     *
     * @return IPage<SysRole>
     */
    @PostMapping("/list")
    public R list() {
        return R.success(sysRoleService.listRole());
    }


}